const { log } = require('console')
const fs = require('fs')
const path = require('path')
const path1 = path.join(__dirname, './book.txt')
const path2 = path.join(__dirname, './copyBook.txt')

const readStream = fs.createReadStream(path1, 'utf-8')
const writeStream = fs.createWriteStream(path2, 'utf-8')

// 将可读流的数据写入到可写流中 连接🔗管道
readStream.pipe(writeStream)

// 监听可读流的数据事件 中间过程 (类似节流形式 每一次拷贝一点慢慢累计起来，提高性能)
readStream.on('data', (chunk) => {
  console.log(chunk, '----- 文件流📃正在拷贝 -----')
})
// 监听可读流的数据事件 完成回调
readStream.on('end', () => {
  console.log('copy done')
})
